<% layout("/inc/layout_page.html"){ %>

<form action="${BASE}/admin/cms/CmsArticle/save" id="form_save" method="post">
<input type="hidden" id="id" name="id" value="${obj.id}">
<input type="hidden" id="sid" name="sid" value="${obj.sid}">
<input type="hidden" id="columnId" name="columnId" value="${obj.columnId}" />
<div class="box">
  <div class="box-header">
    <h4 class="box-title"><i class="fa fa-bars"></i> 修改文章表</h4>
    <div class="box-tools">
      <button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-save"></i> 保存</button>
      <a href="javascript:;" onclick="layer_close()" class="btn btn-info btn-sm"><i class="fa fa-chevron-left"></i> 返回</a>
    </div>
  </div>
  <div class="box-body">
    <table class="table tform table-bordered">
      <tr>
        <th width="20%"><label for="parentName">所属栏目：</label></th>
        <td>
          <div class="col-xs-8">
          <div class="input-group">
            <input type="text" id="columnName" name="columnName" value="${obj.columnName!}" class="form-control" readonly="readonly" >
            <span class="input-group-btn" id="btn_span_parentIds"><button type="button" class="btn btn-info btn-flat"><i class="fa fa-th"></i> 选择所属栏目</button></span>
          </div>
          </div>
          <div class="col-xs-4">&nbsp;</div>
        </td>
      </tr>
      <tr>
        <th><label for="title"><i class="required">*</i>文章标题：</label></th>
        <td>
          <div class="col-xs-8"><input id="title" name="title" value="${obj.title}" type="text" class="form-control"></div>
          <div class="col-xs-4">&nbsp;</div>
        </td>
      </tr>
      <tr>
        <th><label for="link">文章链接：</label></th>
        <td>
          <div class="col-xs-8"><input id="link" name="link" value="${obj.link}" type="text" class="form-control"></div>
          <div class="col-xs-4">&nbsp;</div>
        </td>
      </tr>
      <tr>
        <th><label for="useColTpl">是否自定义模板：</label></th>
        <td>
          <div class="col-xs-8">
          <label class="control-label">&nbsp;<input type="radio" name="useColTpl" class="minimal" value="0" ${obj.useColTpl==0?"checked"}> 使用栏目模板&nbsp;&nbsp;</label>
          <label class="control-label">&nbsp;<input type="radio" name="useColTpl" class="minimal" value="1" ${obj.useColTpl==1?"checked"}> 使用自定义模板&nbsp;&nbsp;</label>
          </div>
          <div class="col-xs-4">&nbsp;</div>
        </td>
      </tr>
      <tr id="div_radio_listtpl">
        <th><label for="customListView">列表模板：</label></th>
        <td>
          <div class="col-xs-4"><input id="customListView" name="customListView" value="${obj.customListView}" type="text" class="form-control"></div>
          <div class="col-xs-4">
            <select class="form-control" id="select_tpl_list" onchange="changeTplList(this.value)">
				<option value="0">不选择</option>
            </select>
          </div>
          <div class="col-xs-4">&nbsp;</div>
        </td>
      </tr>
      <tr id="div_radio_contenttpl">
        <th><label for="customContentView">内容模板：</label></th>
        <td>
          <div class="col-xs-4"><input id="customContentView" name="customContentView" value="${obj.customContentView}" type="text" class="form-control"></div>
          <div class="col-xs-4">
            <select class="form-control" id="select_tpl_content" onchange="changeTplContent(this.value)">
				<option value="0">不选择</option>
            </select>
          </div>
          <div class="col-xs-4">&nbsp;</div>
        </td>
      </tr>
      <tr>
        <th><label for="allowComment">是否允许评论：</label></th>
        <td>
          <div class="col-xs-8">
          <label class="control-label">&nbsp;<input type="radio" name="allowComment" class="minimal" value="1" ${obj.allowComment==1?"checked"}> 是&nbsp;&nbsp;</label>
          <label class="control-label">&nbsp;<input type="radio" name="allowComment" class="minimal" value="0" ${obj.allowComment==0?"checked"}> 否&nbsp;&nbsp;</label>
          </div>
          <div class="col-xs-4">&nbsp;</div>
        </td>
      </tr>
      <tr>
        <th><label for="isAudit">是否需要审核：</label></th>
        <td>
          <div class="col-xs-8">
          <label class="control-label">&nbsp;<input type="radio" name="isAudit" class="minimal" value="1" ${obj.isAudit==1?"checked"}> 是&nbsp;&nbsp;</label>
          <label class="control-label">&nbsp;<input type="radio" name="isAudit" class="minimal" value="0" ${obj.isAudit==0?"checked"}> 否&nbsp;&nbsp;</label>
          </div>
          <div class="col-xs-4">&nbsp;</div>
        </td>
      </tr>
      <tr>
        <th><label for="description">描述、摘要：</label></th>
        <td>
          <div class="col-xs-8"><textarea id="description" name="description" type="text" class="form-control">${obj.description}</textarea></div>
          <div class="col-xs-4">&nbsp;</div>
        </td>
      </tr>
      <tr>
        <th><label for="videoCode">视频脚本：</label></th>
        <td>
          <div class="col-xs-8"><textarea id="videoCode" name="videoCode" type="text" class="form-control">${obj.videoCode}</textarea></div>
          <div class="col-xs-4">&nbsp;</div>
        </td>
      </tr>
      <tr>
        <th><label for="keywords">关键字：</label></th>
        <td>
          <div class="col-xs-8"><input id="keywords" name="keywords" value="${obj.keywords}" type="text" class="form-control"></div>
          <div class="col-xs-4">&nbsp;</div>
        </td>
      </tr>
      <tr>
        <th><label for="image">文章图片：</label></th>
        <td>
          <div class="col-xs-3">
            <input id="image" name="image" type="hidden">
            <% if(isEmpty(obj.image)){ %>
            <img id="fileImage" src="" class="img-thrum">
            <% } else { %>
            <img id="fileImage" src="${IMAGEPATH}/${obj.image!}" class="img-thrum">
            <% } %>
            <span id="fileInfo"></span>
          </div>
          <div class="col-xs-9"><span id="picker">选择图片</span></div>
        </td>
      </tr>
      <tr>
        <th><label for="content">文章内容：</label></th>
        <td>
          <div class="col-xs-9">
              <script id="content" name="content" type="text/plain">${obj.content}</script>
              <script type="text/javascript" src="${STATIC}/lib/ueditor/ueditor.config.js"></script>
              <script type="text/javascript" src="${STATIC}/lib/ueditor/ueditor.all.min.js"></script>
              <script type="text/javascript">UE.getEditor('content');</script>
          </div>
          <div class="col-xs-3">&nbsp;</div>
        </td>
      </tr>
      
    </table>
  </div>
  <div class="box-footer">
    <div class="box-tools pull-right">
      <button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-save"></i> 保存</button>
      <a href="javascript:;" onclick="layer_close()" class="btn btn-info btn-sm"><i class="fa fa-chevron-left"></i> 返回</a>
    </div>
  </div>
</div>
</form>

  <div id="div_menu_select_tree" class="content" style="display: none;">
    <div class="box box-solid">
      <div class="box-body">
        <ul id="ul_menu_select_tree" class="ztree"></ul>
      </div>
    </div>
  </div>
  
<script type="text/javascript">
var isFirstSelectList = true;
function changeTplList(v) {
	if(0==v){
		if(!isFirstSelectList)
			$("#customListView").val("");
	}else{
		$("#customListView").val("/tpl/"+v);
		isFirstSelectList = false;
	}
}
var isFirstSelectContent = true;
function changeTplContent(v) {
	if(0==v){
		if(!isFirstSelectContent)
			$("#customContentView").val("");
	}else{
		$("#customContentView").val("/tpl/"+v);
		isFirstSelectContent = false;
	}
}

function check_radio_uscoltpl(cval){
	if(0==cval){
		$("#div_radio_listtpl").hide();
		$("#div_radio_contenttpl").hide();
		$("#customListView").val("");
		$("#customContentView").val("");
	}else{
		$("#div_radio_listtpl").show();
		$("#div_radio_contenttpl").show();
	}
}
var menuTree;
var tree_setting = {};

function showDailog(){
	if(!menuTree){
		$("#ul_menu_select_tree").html("<li>没有栏目数据</li>");
	}
	layer.open({
		type: 1,
		shadeClose:true,
		title :'选择所属栏目',
		area: ['80%', '90%'],
		content: $('#div_menu_select_tree'),
		btn: ['确认选择', '取消'],
		btn1: function(index, layero){
			if(menuTree){
				var nodes = menuTree.getSelectedNodes()[0];
				if(nodes){
					$("#form_save #columnId").val(nodes.id);
					$("#form_save #columnName").val(nodes.name);
				}
			};
			layer.close(index);
		},
		btn2: function(index, layero){}
	});
}
function select_parent_menu(){
	if(menuTree){
		showDailog();
	}else{
		$.getJSON("${BASE}/admin/cms/CmsColumns/treeData",{}, function(str){
			$("#ul_menu_select_tree").text("");
			if(str)
				menuTree = $.fn.zTree.init($("#ul_menu_select_tree"), tree_setting, str);
			else
				menuTree = null;
			showDailog();
		});
	}
}
$(function(){

	$.getJSON("${BASE}/admin/cms/CmsColumns/tplList",{}, function(str){
		for(var i in str){
			var html = '<option value="'+str[i].value+'" ';
			if(str[i].value=='${strutil.subString(obj.customListView,5)}')
				html += 'selected';
			html+=' >'+str[i].name+'</option>';
			$("#select_tpl_list").append(html);
			
			var htmlc = '<option value="'+str[i].value+'" ';
			if(str[i].value=='${strutil.subString(obj.customContentView,5)}')
				htmlc += 'selected';
			htmlc+=' >'+str[i].name+'</option>';
			$("#select_tpl_content").append(htmlc);
		}
	});
	
    check_radio_uscoltpl(${obj.useColTpl});
    
    $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
      checkboxClass: 'icheckbox_minimal-blue',
      radioClass: 'iradio_minimal-blue'
    });
	$("#form_save input[name='useColTpl']").on('ifChanged', function(event){
		var cval = $(this).val();
		check_radio_uscoltpl(cval);
	});
	
	$("#form_save #parentName, #form_save #btn_span_parentIds").click(select_parent_menu);
	uploadImage("picker","fileImage","fileInfo","image");
	
	
	$("#form_save").validate({
		errorPlacement: function(error, element) {
			error.appendTo(element.parent().next());
		},
		submitHandler : function(form) {
			layer.load(1, {shade: [0.3,'#fff']});
			$(form).ajaxSubmit({
				dataType:"json",
				success:function( jsondata ){
					layer.closeAll('loading');
					if( jsondata.success){
						parent.toastr.success('保存成功！');
						parent.reload_table();
						layer_close();
					}else{
						parent.toastr.error(jsondata.msg);
					}
				}
			});
		},
		rules : {
			title : {
				required : true
			}
		}, 
		messages : { 
			title : { 
				required : "标题不能为空"
			}
		}
	});
});
</script>
<% } %>